<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html> 
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
		<title><?php echo C('WEB_SITE_TITLE');?></title>
		<link rel="stylesheet" href="/Public/Home/css/common.css">
		<link rel="stylesheet" href="/Public/Home/css/main.css">
		<script src="/Public/Home/js/zepto.js"></script>
		<script src="/Public/Home/js/delIOS_huitan.js"></script>
<script>
function deladdress(id)
{
	$.ajax({
			//提交数据的类型 POST GET
			type:"POST",
			//提交的网址
			url:"/index.php?s=/Member/UserAddress/del",
			//提交的数据
			data:{'id':id},
			//返回数据的格式
			datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
			//在请求之前调用的函数
			//成功返回之后调用的函数             
			success:function(json){ 
				tipFun(json.info);
				setTimeout(function(){
					window.location.reload();
				},1000);
			}
		});
}
$(function(){	
		$(".checkbox_btn").click(function(){
		  $.ajax({
				//提交数据的类型 POST GET
				type:"POST",
				//提交的网址
				url:"/index.php?s=/Member/UserAddress/setdefault",
				//提交的数据
				data:{'id':$(this).attr('attrid')},
				//返回数据的格式
				datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
				//在请求之前调用的函数
				//成功返回之后调用的函数
				success:function(json){
					tipFun(json.info);
					setTimeout(function(){
						<?php if($cart_id != null): ?>window.location.href='/index.php?s=/Cart/step2.html&cart_id=<?php echo ($cart_id); ?>&uaddress_id='+$(this).attr('attrid');<?php endif; ?>
					},1000);
				}
			});
        });
})
</script>
	</head>
	<body class="box">
		<!--提示文字-->
		<div class="tip" style="opacity: 0;z-index: -1"></div>
		<!--正文区域-->
		<div id="dingdanShouhuoTop" class="topBackTitle">
			<div class="contain maxWidth">
				<a class="hz back" href="javascript:history.go(-1);">&#xe600;</a>收货地址
			</div>
		</div>
		<div id="dingdanShouhuoMain" class="fastscroll">
			<div class="contain maxWidth">
				<ul>
					<?php if(is_array($list)): $i = 0; $__LIST__ = $list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$item): $mod = ($i % 2 );++$i;?><li>
						<div class="content" onclick="javascript:tocart(<?php echo ($item["id"]); ?>);">
							<p class="maininfo">
								<span class="name"><?php echo ($item["name"]); ?></span><span class="tel"><?php echo ($item["mobile"]); ?></span>
							</p>
							<p class="addr">
								<?php echo ($item["area"]); ?> <?php echo ($item["address"]); ?>
							</p>
						</div>
						<div class="bot">
							<div class="left setdefault">
								<span class="circle checkbox_btn"  attrid="<?php echo ($item["id"]); ?>">
									<span class="hz  <?php if($item["is_default"] == 1): ?>active<?php endif; ?>">&#xe613;</span>
								</span>
								<a href="javascript:;" class="checkbox_btn" attrid="<?php echo ($item["id"]); ?>">设为默认</a>
							</div>
							<div class="right del">
								<!--
								<?php echo U('UserAddress/del',array('id'=>$item['id'],'cart_id'=>$cart_id));?>">
								-->
								<a href="javascript:deladdress(<?php echo ($item["id"]); ?>)">
									<span class="hz">&#xe618;</span>删除
								</a>
							</div>
							<div class="right edit">
					<?php if($cart_id != null): ?><!--
					<a href="/index.php?s=/Cart/step2.html&cart_id=<?php echo ($cart_id); ?>&uaddress_id=<?php echo ($item["id"]); ?>" class="r">选择</a>
					--><?php endif; ?>
								<a href="<?php echo U('UserAddress/edit',array('id'=>$item['id'],'cart_id'=>$cart_id));?>">
									<span class="hz">&#xe619;</span>编辑
								</a>
							</div>
						</div>
					</li><?php endforeach; endif; else: echo "" ;endif; ?>
					
				</ul>
			</div>
		</div>
		<div id="dingdanShouhuoBot">
			<div class="contain maxWidth">
				<a href="javascript:;" onclick="javascript:toaddAddr();" class="addbtn">新建地址</a>
			</div>
		</div>

		<script>
		var cart = "<?php echo ($cart_id); ?>",paytype="<?php echo ($_GET['paytype']); ?>",sendtype="<?php echo ($_GET['sendtype']); ?>",couponid="<?php echo ($_GET['coupon_id']); ?>";
		var spelid="<?php echo ($_GET['spell_id']); ?>",team_id="<?php echo ($_GET['team_id']); ?>",depot="<?php echo ($_GET['depot']); ?>";
		function toaddAddr(){
			var url = "/index.php?s=/Member/UserAddress/add";
			if(cart!=""){
				url+="&cart_id="+cart+"&paytype="+paytype+"&sendtype="+sendtype;
				if(couponid!="")url+="&coupon_id="+couponid;
				if(depot!="")url+="&depot="+depot;
			}
			if(spelid!=""){
				url+="&team_id="+team_id+"&spell_id="+spelid+"&paytype="+paytype;
			}
			location.href=url;
		}
		//点击地址跳转到确认订单页面
		function  tocart(id){
			var cart = "<?php echo ($cart_id); ?>",paytype="<?php echo ($_GET['paytype']); ?>",sendtype="<?php echo ($_GET['sendtype']); ?>",couponid="<?php echo ($_GET['coupon_id']); ?>";
			if(cart!=""){
				url = "<?php echo U('/Home/Cart/step2');?>&cart_id="+cart+"&uaddress_id="+id+"&paytype="+paytype+"&sendtype="+sendtype;
				if(couponid!="")url+="&coupon_id="+couponid;
				if(depot!="")url+="&depot_id="+depot;
				location.href=url;
			}
			var spelid="<?php echo ($_GET['spell_id']); ?>";
			if(spelid!=""){
				location.href = "<?php echo U('/Home/Cart/step3');?>&team_id"+team_id+"&spell_id="+spelid+"&uaddress_id="+id+"&paytype="+paytype;
			}
		}
		
			//返回按钮
			//$('#dingdanShouhuoTop .back').on('tap',function(){
				/*window.location.href='<?php echo U('Index/baseinfo');?>';*/
				//location.href = history.go(-1);
			//});

			//tip
			function tipFun(str){
				$('.tip').text(str).css({
					'opacity':'1',
					'z-index':'9999'
				});
				setTimeout(function(){
					$('.tip').css('opacity','0');
					setTimeout(function(){
						$('.tip').css('z-index','-1');
					},300);
				},1300);
			}

			//点击 设为默认
			$('#dingdanShouhuoMain li .bot .left a').on('tap',function(){
				$('#dingdanShouhuoMain li .bot .left .circle .active').removeClass('active');
				$(this).siblings('.circle').find('.hz').addClass('active');
			});

			//点击 设为默认前面的圈
			$('#dingdanShouhuoMain li .bot .left .circle').on('click',function(){
				$('#dingdanShouhuoMain li .bot .left .circle .active').removeClass('active');
				$(this).find('.hz').addClass('active');
			});
		</script>
	</body>
</html>